package com.yizhuoyan.study.monoflux;

import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.concurrent.locks.LockSupport;

/**
 * Hello world!
 *
 */
public class App{
    public static void main( String[] args )throws Exception{
		var flux = Mono.just(1).then(Mono.defer(()->{
			return Mono.empty();
		}));
		flux.subscribe(System.out::println);
	}
    public static void main1( String[] args )throws Exception{
        var flux = Flux.just(1, 2, 3);
        flux.doOnError(e->{
            System.out.println("on err"+e.getLocalizedMessage());
        });
        flux.subscribe(new Subscriber<>() {
			@Override
			public void onSubscribe(Subscription s) {
                s.request(10);
				System.out.println("Subscription="+s);
			}

			@Override
			public void onNext(Integer v) {
				if (v == 2) {
                    System.out.println("fuck2...");
					throw new RuntimeException("fuck 2");
				}
				System.out.println(v);
			}

			@Override
			public void onError(Throwable t) {
				System.out.println("fuck error");
			}

			@Override
			public void onComplete() {
				System.out.println("onComplete");
			}
		});
    }
}
